<!DOCTYPE HTML>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no"/>

    <!--[if lt IE 9]>
    <script type="text/javascript" src="js/html5shiv.js"></script>
    <script type="text/javascript" src="js/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="h-ui/css/H-ui.min.css"/>
    <link rel="stylesheet" type="text/css" href="h-ui.admin/css/H-ui.admin.css"/>
    <link rel="stylesheet" type="text/css" href="Hui-iconfont/1.0.8/iconfont.css"/>
    <link rel="stylesheet" type="text/css" href="h-ui.admin/skin/default/skin.css" id="skin"/>
    <link rel="stylesheet" type="text/css" href="h-ui.admin/css/style.css"/>
    <!--[if IE 6]>
    <script type="text/javascript" src="js/DD_belatedPNG_0.0.8a-min.js"></script>
    <script>DD_belatedPNG.fix('*');</script>
    <![endif]-->
    <title>图片信息编辑</title>
</head>
<body>
<div class="page-container">
    <form class="form form-horizontal" id="form-picture-edit">
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2"><span class="c-red">*</span>图片标题：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="hidden" value="${image.id}" id="id" name="id">
                <input type="text" class="input-text" value="${image.title}" placeholder="" id="title" name="title">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">图片链接：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="${image.url}" placeholder="" id="url" name="url">
            </div>
        </div>

        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">图片：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <div class="uploader-thum-container">
                    <div id="fileList" style="margin-bottom: 5px"><img src="${image.pic}" alt="" id="preview" width="120"/></div>
                    <span class="btn-upload form-group">
                        <input class="input-text upload-url radius" type="text" name="uploadFile" id="uploadFile"
                               readonly>
                        <a href="javascript:void(0);" class="btn btn-primary radius btn-upload"><i class="Hui-iconfont">&#xe642;</i> 选择图片</a>
                        <input type="file" name="file" class="input-file" onchange="imgPreview(this)"
                               accept="image/gif,image/jpg,image/jpeg,image/png">
                    </span>
                </div>
            </div>
        </div>
        <div class="row cl">
            <label class="form-label col-xs-4 col-sm-2">排序值：</label>
            <div class="formControls col-xs-8 col-sm-9">
                <input type="text" class="input-text" value="${image.sortOrder}" placeholder="" id="sortOrder" name="sortOrder">
            </div>
        </div>
        <div class="row cl">
            <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                <button class="btn btn-primary radius" type="submit"><i class="Hui-iconfont">&#xe632;</i> 修改
                </button>
                <button onClick="layer_close();" class="btn btn-default radius" type="button">
                    &nbsp;&nbsp;取消&nbsp;&nbsp;
                </button>
            </div>
        </div>
    </form>
</div>

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="/js/jquery/jquery-1.8.3.js"></script>
<script type="text/javascript" src="js/layer/2.4/layer.js"></script>
<script type="text/javascript" src="h-ui/js/H-ui.min.js"></script>
<script type="text/javascript" src="h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer /作为公共模版分离出去-->
<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="js/jquery.validation/1.14.0/jquery.validate.js"></script>
<script type="text/javascript" src="js/jquery.validation/1.14.0/validate-methods.js"></script>
<script type="text/javascript" src="js/jquery.validation/1.14.0/messages_zh.js"></script>
<script type="text/javascript">
    function imgPreview(obj) {
        //判断是否支持FileReader
        if (window.FileReader) {
            var reader = new FileReader();
        } else {
            alert("您的设备不支持图片预览功能，如需该功能请升级您的设备！");
        }
        //获取文件
        var file = obj.files[0];
        var imageType = /^image\//;
        //是否是图片
        if (!imageType.test(file.type)) {
            alert("请选择图片！");
            return;
        }
        //读取完成
        reader.onload = function (e) {
            //获取图片dom
            var img = document.getElementById("preview");
            //图片路径设置为读取的图片
            img.src = e.target.result;
        };
        reader.readAsDataURL(file);
    }

    $("#form-picture-edit").validate({
        rules: {
            title: {
                required: true
            },
            url: {
                required: true
            },
            sortOrder: {
                required: true,
                digits: true
            }
        },
        messages: {
            title: {
                required: "请填写图片标题"
            },
            url: {
                required: "请填写图片链接"
            },
            sortOrder: {
                required: "请填写排序值",
                digits: "请输入正确的整数"
            }
        },
        onkeyup: true,
        focusCleanup: true,
        onsubmit: true,
        submitHandler: function (form) {
            var myForm = document.querySelector("#form-picture-edit");
            var data = new FormData(myForm);
            $.ajax({
                url: "updateImage",
                type: "POST",
                data: data,
                contentType: false,
                processData: false,
                dataType: "json",
                success: function (data) {
                    if (data == true) {
                        layer.msg("修改成功！", {icon: 1, time: 500}, function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            parent.location.reload();
                            parent.layer.close(index);
                        })
                    } else {
                        layer.msg("修改失败！", {icon: 5, time: 500});
                    }
                }
            })
        }
    });

</script>
</body>
</html>